package com.zhanggm.springcould.user.controller;

import com.zhanggm.springcloud.user.api.model.User;
import com.zhanggm.springcould.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @Value("${server.port}")
    private Integer serverPort;


    /**
     * 根据Id，查询用户名称
     * @param id
     * @return
     */
//    @RequestMapping(value = "/getUsernameById/",method = RequestMethod.GET)
    @GetMapping("/getUsernameById")
    public String getUsernameById(@RequestParam("id") Integer id){
        return userService.getUsernmaeById(id);
    }

    /**
     * 根据用户Id，查询用户信息
     * @param id
     * @return
     */
    @GetMapping("/getUserById")
    public User getUserById(@RequestParam("id") Integer id){
//        log.info("getUserById:{}",id);
//        log.info("serverPort:{}",serverPort);
        return userService.getUserById(id);
    }

    /**
     * 根据用户id，查询用户信息
     * @param user
     * @return
     */
    @PostMapping("/getUserByUser")
    public User getUserByUser(@RequestBody User user){
        return userService.getUserById(user.getId());
    }

}
